#ifndef IMGPREPROCESSING_H
#define IMGPREPROCESSING_H

#include "opencv2/core/core.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <QDebug>

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace cv;
using namespace std;

class ImgPreProcessing
{
private:

    int cols;
    int rows;
    int background_hLow = 50;
    int background_hHigh = 150;
    int background_sLow = 80;
    int background_sHigh = 200;
    int background_vLow = 0;
    int background_vHigh = 200;
    int face_hLow = 0;
    int face_hHigh = 100;
    int face_sLow = 0;
    int face_sHigh = 150;
    int face_vLow = 50;
    int face_vHigh = 220;
    int line_width = 1;

    double gray_average;

    vector<int> binary_x;
    vector<int> binary_y;
    vector<int> gray_value;

    Mat src_image;
    Mat hsv_image;
    Mat morphology_image;
    Mat cut_image;
    Mat gray_image;
    Mat decentralized_image;
    Mat draw_face_image;

    Scalar hsv_min = Scalar(background_hLow,background_sLow,background_vLow);
    Scalar hsv_max = Scalar(background_hHigh,background_sHigh,background_vHigh);
    Scalar face_hsv_min = Scalar(face_hLow,face_sLow,face_vLow);
    Scalar face_hsv_max = Scalar(face_hHigh,face_sHigh,face_vHigh);
    Scalar rect_color = Scalar(255,0,0);


    // @brief inrange hsv
    void inRangeHSV();

    // @brief morphology open
    // @return face area rect
    Rect imgMorphology();

    // @brief cut img with rect
    void imgCut(Rect rct);

    // @brief BGR2Gray
    void cuttedImg2Gray();

    // @brief resize vector<vector<int> > gray_value
    // @param gray_value rows
    // @param gray_value cols
    void resizeGrayValue(int rows,int cols);

    // @brief make gray_value from gray_image
    void makeGrayValue();

    // @brief gray_value - gray_average
    void grayValueSubAverage();

    // @brief gray_value2decentralized_image
    void grayValue2Dec();

public:
    ImgPreProcessing(const Mat img);

    void makePreProcessing();

    // @brief return src_image
    // @return src_image
    Mat getSrcImg();

    // @brief return morphology_image
    // @return morphology_image
    Mat getMorphologyImg();

    // @brief return hsv_image
    // @return hsv_image
    Mat getHSVImg();

    // @brief return cut_image
    // @return cut_image
    Mat getCutImg();

    // @brief return gray_image
    // @return gray_image
    Mat getCuttedGrayImg();

    // @brief return decentralized_image
    // @return decentralized_image
    Mat getDecentralizedImg();

    // @brief return decentralized_image
    // @return decentralized_image
    int getSumnumber();

    // @brief return gray_value
    // @return gray_value
    vector<int> getGrayValue();

};

#endif // IMGPREPROCESSING_H
